test_building <- readRDS('test_building.Rds')
test_streets <- readRDS('test_streets.Rds')
test_parcels <- readRDS('test_parcels.Rds')
test_area <- readRDS("test_area.Rds")
tm_shape(test_parcels) + tm_polygons("green", alpha = 0.4) +
tm_shape(test_building, is.master = TRUE) + tm_polygons(col = "blue") +
tm_shape(test_streets) + tm_lines(col = "red")
buildings_line_centroids <- st_segments(test_building) %>%
rename(geometry = result) %>%
st_centroid()
##
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|== | 4%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 15%
|
|=========== | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|============== | 21%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================ | 24%
|
|================= | 24%
|
|================= | 25%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 26%
|
|=================== | 27%
|
|=================== | 28%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 29%
|
|===================== | 30%
|
|===================== | 31%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================= | 48%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 49%
|
|=================================== | 50%
|
|=================================== | 51%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 59%
|
|========================================== | 60%
|
|========================================== | 61%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 69%
|
|================================================= | 70%
|
|================================================= | 71%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|=================================================== | 74%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|======================================================== | 81%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 89%
|
|=============================================================== | 90%
|
|=============================================================== | 91%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 99%
|
|======================================================================| 100%
nn <- st_nn(buildings_line_centroids, test_streets, returnDist = TRUE, progress = FALSE)
buildings_line_centroids$nn_dst <- unlist(nn$dist)
closest_centroid <- buildings_line_centroids %>%
group_by(FID) %>%
top_n(-1)
tm_shape(test_streets) + tm_lines(col = "red") +
tm_shape(buildings_line_centroids) + tm_dots("green") +
tm_shape(closest_centroid) + tm_dots("blue")
setback_line <- st_connect(closest_centroid, test_streets, progress = FALSE)
setback_line <- st_as_sf(setback_line)
setback_line_over_parcel <- st_intersection(setback_line, test_parcels) %>%
mutate(length_ft = as.numeric(st_length(.))) %>%
select(length_ft)
tm_shape(test_building, is.master = TRUE) + tm_polygons(col = "black") +
tm_shape(test_streets) + tm_lines(col = "green") +
tm_shape(setback_line) + tm_lines(col = "blue", lwd = 2) +
tm_shape(setback_line_over_parcel) + tm_lines(col = "red", lwd = 2)
setback_parcel_only_centroid <- st_centroid(setback_line_over_parcel)
setback_centroid <- setback_line %>%
mutate(length_ft = as.numeric(st_length(.))) %>%
st_centroid()
summary_grid <- st_make_grid(test_area, cellsize = 1320, square = FALSE, crs = 2236) %>% st_as_sf() %>%
mutate(id = row_number()) %>%
select(id)
summary_grid_parcel <- st_join(summary_grid, setback_parcel_only_centroid) %>%
group_by(id) %>%
summarize(median_parcel_setback_ft = mean(length_ft))
summary_grid_centroid <- st_join(summary_grid, setback_centroid) %>%
group_by(id) %>%
summarize(median_setback_centerline = mean(length_ft))
parcel_length <- tm_shape(summary_grid_parcel) + tm_polygons(col = "median_parcel_setback_ft", breaks = c(10, 20, 30, 50, 100, 200))
full_length <- tm_shape(summary_grid_centroid) + tm_polygons(col = "median_setback_centerline", breaks = c(10, 20, 30, 50, 100, 200))
tmap_arrange(parcel_length, full_length, sync = TRUE)